$(function() {
	$("#jqGridZN").jqGrid({
		url: baseURL + 'gaokaobaobei/zhaosheng/myOutstandinglist',
		datatype: "json",
		colModel: [{
				label: '姓名',
				name: 'name',
				index: 'name',
				width: 90
			},
			{
				label: '考号',
				name: 'candidateNumber',
				index: 'candidate_number',
				width: 120
			},
			{
				label: '文理属性',
				name: 'wlProperty',
				index: 'wl_property',
				width: 90
			},
			{
				label: '分数',
				name: 'score',
				index: 'score',
				width: 90
			},
			{
				label: '高中',
				name: 'highSchool',
				index: 'high_school',
				width: 120
			},
			{
				label: '联系电话',
				name: 'phone',
				index: 'phone',
				width: 120
			},
			{
				label: '报备时间',
				name: 'creationDate',
				index: 'creation_date',
				width: 150
			},
			{
				label: '备注',
				name: 'candidateNumber',
				index: 'candidate_number',
				width: 130,
				formatter: function(data, a, rows) {
					if(rows.type == '等待录取结果') {
						return `备注:`;
					} else if(rows.type == '审核未通过') {
						return `<font color="#228b22">备注:${rows.school}</font>&nbsp;&nbsp;<font color="red">原因:${rows.major}</font> `;
					} else {
						return `<font color="#228b22">备注:${rows.school}</font> `;
					}
					if(rows.type == '等待录取结果') {
						return `${data}<br>备注:<input id="xk${data}" />`;
					} else if(rows.type == '审核未通过') {
						return `${data}<br><font color="#228b22">备注:${rows.school}</font>&nbsp;&nbsp;<font color="red">原因:${rows.major}</font> `;
					} else {
						return `${data}<br><font color="#228b22">备注:${rows.school}</font> `;
						if(rows.type == '等待录取结果') {
							return `备注:<input id="xk${data}" />`;
						} else if(rows.type == '审核未通过') {
							return `<font color="#228b22">备注:${rows.school}</font>&nbsp;&nbsp;<font color="red">原因:${rows.major}</font> `;
						} else {
							return `<font color="#228b22">备注:${rows.school}</font> `;
						}
					}

				}
			},
			{
				label: '操作',
				name: 'cz',
				index: 'cz',
				width: 100,
				formatter: function(data, a, rows) {
					if(rows.type == '审核通过') {
						return `<font color="#228b22">审核通过</font>`
					}
				}
			},
		],
		viewrecords: true,
		height: 385,
		rowNum: 10,
		rowList: [10, 30, 50],
		rownumbers: true,
		rownumWidth: 25,
		autowidth: true,
		multiselect: true,
		pager: "#jqGridPagerZN",
		jsonReader: {
			root: "page.list",
			page: "page.currPage",
			total: "page.totalPage",
			records: "page.totalCount"
		},
		prmNames: {
			page: "page",
			rows: "limit",
			order: "order"
		},
		gridComplete: function() {
			//隐藏grid底部滚动条
			$("#jqGrid").closest(".ui-jqgrid-bdiv").css({
				"overflow-x": "hidden"
			});
		},
	});
	vm.count()
});

function select(Admissionstype) {
	var pageZN = $("#jqGridZN").jqGrid('getGridParam', 'page');
	$("#jqGridZN").jqGrid('setGridParam', {
		postData: {
			"name": localStorage.username,
			"Admissionstype": vm.Admissionstype
		},
		page: pageZN
	}).trigger("reloadGrid");
}

var vm = new Vue({
	el: '#rrapp',
	data: {
		shengben: 0,
		danzhao: 0,
		kaoyan: 0,
		xiakao: 0,
		showList: 0,
		showList2: true,
		showList3: false,
		title: null,
		username: localStorage.username,
		agency: {},
		Admissionstype: "",
	},
	methods: {
		queryZN: function() {
			var pageZN = $("#jqGridZN").jqGrid('getGridParam', 'page');
			$("#jqGridZN").jqGrid('setGridParam', {
				postData: {
					"name": localStorage.username,
					"Admissionstype": vm.Admissionstype
				},
				page: pageZN
			}).trigger("reloadGrid");
		},
		query: function() {
			vm.reload();
		},
		add: function() {
			vm.showList = 1;
			vm.title = "新增";
			vm.agency = {};
		},
		update: function(event) {
			var id = getSelectedRow();
			if(id == null) {
				return;
			}
			vm.showList = 1;
			vm.title = "修改";
			vm.getInfo(id)
		},
		saveOrUpdate: function(event) {
			var url = vm.agency.id == null ? "gaokaobaobei/agency/save" : "gaokaobaobei/agency/update";
			$.ajax({
				type: "POST",
				url: baseURL + url,
				contentType: "application/json",
				data: JSON.stringify(vm.agency),
				success: function(r) {
					if(r.code === 0) {
						alert('操作成功', function(index) {
							vm.reload();
						});
					} else {
						alert(r.msg);
					}
				}
			});
		},
		del: function(event) {
			var ids = getSelectedRows();
			if(ids == null) {
				return;
			}
			confirm('确定要删除选中的记录？', function() {
				$.ajax({
					type: "POST",
					url: baseURL + "gaokaobaobei/agency/delete",
					contentType: "application/json",
					data: JSON.stringify(ids),
					success: function(r) {
						if(r.code == 0) {
							alert('操作成功', function(index) {
								$("#jqGrid").trigger("reloadGrid");
							});
						} else {
							alert(r.msg);
						}
					}
				});
			});
		},
		getInfo: function(id) {
			$.get(baseURL + "gaokaobaobei/agency/info/" + id, function(r) {
				vm.agency = r.agency;
			});
		},
		reload: function(event) {
			vm.showList = 0;
			var page = $("#jqGrid").jqGrid('getGridParam', 'page');
			$("#jqGrid").jqGrid('setGridParam', {
				page: page
			}).trigger("reloadGrid");
		},
		count: function() {
			var username = localStorage.username
			$.ajax({
				type: "POST",
				url: baseURL + "gaokaobaobei/agency/countOutstanding",
				contentType: "application/json",
				data: username,
				success: function(r) {
					console.log(r)
					vm.shengben = r.countOutstanding[0].shengben
					vm.danzhao = r.countOutstanding[0].danzhao
					vm.kaoyan = r.countOutstanding[0].kaoyan
					vm.xiakao = r.countOutstanding[0].xiakao
				}
			});
		},
	}
})